<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.net.URLDecoder" %>
<%@ page import="com.model.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}

.tabfont01 {
	font-family: "宋体";
	font-size: 9px;
	color: #555555;
	text-decoration: none;
	text-align: center;
}

.font051 {
	font-family: "宋体";
	font-size: 12px;
	color: #333333;
	text-decoration: none;
	line-height: 20px;
}

.font201 {
	font-family: "宋体";
	font-size: 12px;
	color: #FF0000;
	text-decoration: none;
}

.button {
	font-family: "宋体";
	font-size: 14px;
	height: 37px;
}

html {
	overflow-x: auto;
	overflow-y: auto;
	border: 0;
}
-->
</style>

<link href="../css/css.css" rel="stylesheet" type="text/css" />
<link href="../css/style.css" rel="stylesheet" type="text/css" />
<script language="JavaScript" type="text/javascript">
	function selectAll() {
		var obj = document.fom.elements;
		for ( var i = 0; i < obj.length; i++) {
			if (obj[i].name == "delid") {
				obj[i].checked = true;
			}
		}
	}

	function unselectAll() {
		var obj = document.fom.elements;
		for ( var i = 0; i < obj.length; i++) {
			if (obj[i].name == "delid") {
				if (obj[i].checked == true)
					obj[i].checked = false;
				else
					obj[i].checked = true;
			}
		}
	}

	function link() {
		document.getElementById("fom").action = "list_CLCX.jsp";
		document.getElementById("fom").submit();
	}
</script>
</head>

<body class="ContentBody">
	<%
		Connection con = DataBase.getConnection();
				
		request.setCharacterEncoding("UTF-8");
		String lpn = URLDecoder.decode(request.getParameter("lpn"),"UTF-8");
		PreparedStatement pstmtInfo = con
				.prepareStatement("SELECT * FROM car WHERE lpn=?");
		pstmtInfo.setString(1, lpn);
		ResultSet rsInfo = pstmtInfo.executeQuery();
		if (!rsInfo.next()) {
	%>
	无效车牌号！请勿作非法输入！
	<%
		} else {
			Boolean status = false; //	false indicates car is not out, when true is in reverse
			PreparedStatement pstmtCheck = con
					.prepareStatement("SELECT status FROM car WHERE lpn=?");
			pstmtCheck.setString(1, lpn);
			ResultSet rsCheck = pstmtCheck.executeQuery();
			rsCheck.next();
			status = rsCheck.getBoolean("status");
			ResultSet rsStatus = null;
			if (status) {
				PreparedStatement pstmtOut = con
						.prepareStatement("SELECT * FROM carry WHERE lpn=? ORDER BY time DESC LIMIT 0,1");
				pstmtOut.setString(1, lpn);
				rsStatus = pstmtOut.executeQuery();
				if (!rsStatus.next()) {
	%>
	遭遇车辆最近出车数据错误，请重新进入
	<%
		}
			}
	%>
	<form name="fom" id="fom" method="post" action="">
		<table width="100%" border="0" cellspacing="0" cellpadding="0">

			<tr>
				<td height="30"><table width="100%" border="0" cellspacing="0"
						cellpadding="0">
						<tr>
							<td>
								<table width="98%" border="0" align="center" cellpadding="0"
									cellspacing="0">

								</table>
							</td>
						</tr>
					</table></td>
			</tr>
			<tr>
				<td><table id="subtree1" style="DISPLAY:" width="100%"
						border="0" cellspacing="0" cellpadding="0">

						<tr>
							<td><table width="95%" border="0" align="center"
									cellpadding="0" cellspacing="0">

									<tr>
										<td height="40" class="font42"><table width="100%"
												border="0" cellpadding="4" cellspacing="1" bgcolor="#464646"
												class="newfont03">

												<tr>
													<td height="20" colspan="4" align="center"
														class="tablestyle_title">车辆信息列表</td>
												</tr>
												<tr>
													<td width="15%" height="20" align="right" bgcolor="#FFFFFF">车牌号:</td>
													<td width="35%" align="left" bgcolor="#FFFFFF"><%=rsInfo.getString("lpn")%></td>
													<td width="15%" height="20" align="right" bgcolor="#FFFFFF">车辆型号:</td>
													<td width="35%" bgcolor="#FFFFFF"><%=rsInfo.getString("model")%></td>
												</tr>
												<tr>
													<td height="20" align="right" bgcolor="#FFFFFF">可载人数:</td>
													<td bgcolor="#FFFFFF"><%=rsInfo.getString("carry")%></td>
													<td height="20" align="right" bgcolor="#FFFFFF">出车人:</td>
													<td bgcolor="#FFFFFF"><%=status ? rsStatus.getString("user") : ""%></td>
												</tr>
												<tr>
													<td height="20" align="right" bgcolor="#FFFFFF">出发地:</td>
													<td bgcolor="#FFFFFF"><%=status ? rsStatus.getString("from") : ""%></td>
													<td height="20" align="right" bgcolor="#FFFFFF">目的地:</td>
													<td bgcolor="#FFFFFF"><%=status ? rsStatus.getString("to") : ""%></td>
												</tr>
												<tr>
													<td height="20" align="right" bgcolor="#FFFFFF">出发事由:</td>
													<td bgcolor="#FFFFFF"><%=status ? rsStatus.getString("reason") : ""%></td>
													<td height="20" align="right" bgcolor="#FFFFFF">出发时间:</td>
													<td bgcolor="#FFFFFF"><%=status ? rsStatus.getString("time") : ""%></td>
												</tr>
												<tr>
													<td height="20" align="right" bgcolor="#FFFFFF">备注:</td>
													<td bgcolor="#FFFFFF" colspan="3"><%=status ? rsStatus.getString("user") : ""%>
													</td>
												</tr>
												<tr>
													<td height="85" align="right" bgcolor="#FFFFFF">出车记录:</td>
													<td colspan="3" bgcolor="#FFFFFF"><table width="100%"
															align="center" border="0" cellpadding="4" cellspacing="1"
															bgcolor="#464646">
															<tr height="10" align="center" bgcolor="#FFFFFF">
																<td width="20%">出车时间</td>
																<td width="20%">车牌号</td>
																<td width="20%">车牌型号</td>
																<td width="20%">出车人</td>
																<td width="20%">回车情况</td>
															</tr>
															<%
																PreparedStatement pstmtCarry = con.prepareStatement("SELECT time,user,back FROM carry WHERE lpn=? ORDER BY time DESC");
																pstmtCarry.setString(1, lpn);
																ResultSet rsCarry = pstmtCarry.executeQuery();
																while( rsCarry.next() ){
																	String backTime = rsCarry.getString(3);
															%>
															<tr height="20" bgcolor="#FFFFFF">
																<td><%=rsCarry.getString(1)%></td>
																<td><%=lpn%></td>
																<td><%=rsInfo.getString("model")%></td>
																<td><%=rsCarry.getString(2)%></td>
																<td><%=backTime==null?"未回":backTime %></td>
															</tr>
															<%}
																rsCarry.close();
															%>
														</table></td>
												</tr>
											</table></td>
									</tr>
								</table></td>
						</tr>
					</table>
					<table width="95%" border="0" align="center" cellpadding="0"
						cellspacing="0">
						<tr>
							<td height="6"><img src="../images/spacer.gif" width="1"
								height="1" /></td>
						</tr>
						<tr>
							<td height="33"><table width="100%" border="0"
									align="center" cellpadding="0" cellspacing="0"
									class="right-font08">
									<tr></tr>
								</table></td>
						</tr>
					</table></td>
			</tr>
			<tr>
				<td colspan="2" align="center" height="20px"><input style="height:20px"
					type="button" name="Submit2" value="返回" class="button"
					onclick="link();" /></td>
			</tr>
		</table>
	</form>
	<%
		if (rsStatus != null)
				rsStatus.close();
		}
		rsInfo.close();
		con.close();
	%>
</body>
</html>
